﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=704",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "../system/error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab = tabs.getTab("tab$704");
                    tabs.removeTab(tab);
                }
            }
        });
    </script>
</head>
<body>
    <div class="mini-fit">
        <div id="divList" class="mini-fit">
            <div class="mini-toolbar" style="border-bottom: 0;">
                <table >
                    <tr>
                        <td>
                            单位:
                            <input class="mini-textbox" id="key" style="width:140px" emptytext="用户名或单位名称关键字"/>
                            所在地区：
                            <input id="area" style="width:90px" class="mini-combobox" url="../data/system.aspx?method=CbxAreaNoAll" textField="di_name" valueField="di_code" value="0"/>
                            <a class="mini-button" iconcls="icon-search" plain="true" onclick="search()">查询</a>
                            <span class="separator"></span>
                            <a class="mini-button" plain="true" iconcls="icon-add" onclick="addRow()">新增</a>
                            <a class="mini-button" plain="true" iconcls="icon-remove" onclick="delRows()">删除</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="mini-fit">
                <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" allowresize="true"
                    url="../data/system.aspx?method=GetBaseList" idfield="cu_no" multiselect="true" sizeList="[15,20,50,100]" pageSize="15">
                    <div property="columns">
                        <div type="checkcolumn">
                        </div>
                        <div cellCls="actionIcons" name="action" width="80px" headeralign="center" align="center" renderer="onActionRenderer" cellstyle="padding:0;">操作</div>
                        <div field="cu_name" headeralign="center" align="center" allowsort="true" renderer="onNameRenderer">单位名称</div>
                        <div field="trade" width="180px" headeralign="center" align="center" allowsort="true">所属行业</div>
                        <div field="property" width="100px" headeralign="center" align="center" allowsort="true">企业性质</div>
                        <div field="area" width="80px" headeralign="center" align="center" allowsort="true">所在地区</div>
                        <div field="cu_logintime" width="80px" align="center" allowsort="true" headeralign="center" dateformat="yyyy-MM-dd">最后登录时间</div>
                        <div field="cu_contact" width="80px" headeralign="center" align="center" allowsort="true">联系人</div>
                        <div field="cu_tel" width="80px" headeralign="center" align="center" allowsort="true">联系电话</div>
                        <div field="cu_ok" width="40px" align="center" headeralign="center" allowsort="true" renderer="onOkRenderer">免审</div>
                        <div field="is_count" width="70px" headeralign="center" align="center" renderer="onRecruitRenderer">职位</div>
                    </div>
                </div>
            </div>
        </div>
        <div id="editForm" class="form" style="display: none">
            <fieldset style="border: solid 1px #aaa; width: 720px">
                <legend><strong>企业详细信息</strong><span class="red">( 带 * 号的必须填写)</span></legend>
                <input class="mini-hidden" name="cu_no" id="cu_no"/>
                <table style="padding:5px; width: 100%; ">
                    <tr>
                        <td class="tdtitle" style="width: 100px;">
                            <span style="color: Red">*</span>&nbsp;&nbsp;用户名：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_user" style="width: 280px" required="true" />&nbsp;&nbsp;&nbsp;&nbsp;
                            <input name="cu_ok" class="mini-checkbox" text="免审" value="1"/>
                        </td>
                    </tr>
                    <tr id="trpass">
                        <td class="tdtitle">
                            <span style="color: Red">*</span>&nbsp;&nbsp;密码：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_password" style="width: 280px" required="true" value="888888"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            <span style="color: Red">*</span>&nbsp;&nbsp;单位名称：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_name" style="width: 280px" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            <span style="color: Red">*</span>&nbsp;&nbsp;类型：
                        </td>
                        <td colspan="3">
                            <input class="mini-combobox" name="cu_base" data="Base" required="true"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            营业执照：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_license" style="width: 280px"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            企业性质：
                        </td>
                        <td colspan="3">
                            <input class="mini-combobox" style="width: 180px;" name="cu_property" textfield="di_name"
                                valuefield="di_code" url="../data/system.aspx?method=CbxPoperty" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            <span style="color: Red">*</span>&nbsp;&nbsp;所在地区：
                        </td>
                        <td colspan="3">
                            <input class="mini-combobox" style="width: 180px;" name="cu_area" textfield="di_name"
                                required="true" valuefield="di_code" url="../data/system.aspx?method=CbxAreaNo" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            所属产业：
                        </td>
                        <td colspan="3">
                            <input name="cu_industry" class="mini-checkboxlist" data="CompanyIndustry" repeatItems="3" repeatLayout="table"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            所属行业：
                        </td>
                        <td colspan="3">
                            <input class="mini-combobox" style="width: 180px;" name="cu_trade" textfield="di_name"
                                valuefield="di_code" url="../data/system.aspx?method=CbxTrade" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            <span style="color: Red">*</span>&nbsp;&nbsp;单位地址：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_address" style="width: 280px" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            联系人：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_contact" style="width: 280px"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            联系电话：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_tel" style="width: 280px"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            传真：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_fax" style="width: 280px" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            电子邮箱：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_email" vtype="email" style="width: 280px" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            企业网址：
                        </td>
                        <td colspan="3">
                            <input class="mini-textbox" name="cu_url" style="width: 280px" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle">
                            企业简介：
                        </td>
                        <td colspan="3">
                            <input class="mini-textarea" name="cu_introduce" style="width: 570px; height: 80px" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align:center;padding:5px;">
                            <a class="mini-button" style="width:60px;" onclick="updateRow()" >保存</a>
                            <span style="display:inline-block;width:25px;"></span>
                            <a class="mini-button" style="width:60px;" onclick="cancelRow()">取消</a>
                        </td>
                    </tr>
                </table>
            </fieldset>
        </div>
        <div id="passWindow" class="mini-window" title="重置密码<span class='red'>( 带 * 号的必须填写)</span>" style="width: 360px;" showmodal="true"
            allowresize="false" allowdrag="true" showfooter="true">
            <div id="passform" class="form">
                <input class="mini-hidden" id="cu_no2" name="cu_no" />
                <table style="width: 100%;">
                    <tr>
                        <td class="tdtitle" width="80px">单位名称：</td>
                        <td style="color: Blue">
                            <div id="check">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle"><span class="red">*</span>新密码：</td>
                        <td>
                            <input id="cu_password" name="cu_password" class="mini-password" required="true"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="tdtitle"><span class="red">*</span>确认密码：</td>
                        <td>
                            <input id="cu_password2" name="cu_password2" class="mini-password" required="true" />
                        </td>
                    </tr>
                </table>
            </div>
            <div property="footer" style="text-align: center; padding: 5px;">
                <a class="mini-button" style="width: 80px;" onclick="updatePass()">保存</a>
                <span style="display: inline-block; width: 25px;"></span>
                <a class="mini-button" style="width: 60px;" onclick="closePass()">关闭</a>
            </div>
        </div>
    </div>
    <iframe id="exportIFrame" style="display:none;"></iframe>
    <!--导出Excel相关HTML-->
     <form id="excelForm" action="../data/download.aspx?method=ExcelBase" method="post" target="excelIFrame">
        <input type="hidden" name="key" id="Hidden1" />
        <input type="hidden" name="area" id="Hidden2" />
    </form>
    <iframe id="excelIFrame" name="excelIFrame" style="display:none;"></iframe>
</body>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();
        var grid = mini.get("datagrid1");
        search();

        //查询
        function search() {
            var key = mini.get("key").getValue();
            var area = mini.get("area").getValue();

            $("#Hidden1").val(key);
            $("#Hidden2").val(area);
            grid.load({ key: key, area: area });
            grid.sortBy("cu_no", "desc");
        }

        function onActionRenderer(e) {
            var record = e.record;
            var s = '<span class="icon-edit actionspan" title="修改" onclick="editRow(' + record._uid + ')"></span><span class="separator"></span><span class="icon-reload actionspan" title="重置密码" onclick="retRow(' + record._uid + ')"></span><span class="separator"></span><span class="icon-remove actionspan" title="删除" onclick="delRow(' + record._uid + ')"></span>';
            return s;
        }

        //单位名称显示
        function onNameRenderer(e) {
            var record = e.record;
            var s = '<a class="noline" style="color:Black" title="编  号：' + record.cu_no + '&#13用户名：' + record.cu_user + '">' + record.cu_name + '</a>';
            if (record.cu_color != null && record.cu_color != 'Default')
                s = '<a class="noline" style="color:' + record.cu_color + '" title="编  号：' + record.cu_no + '&#13用户名：' + record.cu_user + '">' + record.cu_name + '</a>';
            if (record.cu_hide == 1) {
                s = s + "<span style='color:Red'>[隐]</span>";
            }
            return s;
        }

        //免审显示
        function onOkRenderer(e) {
            var s;
            if (e.value == 1)
                s = '<font color="Green">是</font>';
            else
                s = '<font color="Red">否</font>';
            return s;
        }

        //招聘显示
        function onRecruitRenderer(e) {
            var s = '<a class="linelink" title="详细" href="javascript:void(0);" onclick="recruitRows(' + e.record._uid + ')">管理</a> (' + e.value + ')';
            return s;
        }

        //新增基地企业
        function addRow() {
            var form = new mini.Form("#editForm");
            form.reset();
            mini.getbyName("cu_user").enable();
            $("#trpass").show();
            $("#editForm").show();
            $("#divList").hide();
        }

        //修改基地企业
        function editRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var form = new mini.Form("#editForm");
                form.loading();
                form.clear();
                $("#trpass").hide();
                $("#editForm").show();
                $("#divList").hide();
                $.ajax({
                    url: "../data/system.aspx?method=GetCompany",
                    data: { id: row.cu_no },
                    success: function (text) {
                        form.unmask();
                        if (text == "out") {
                            $("#divList").show();
                            $("#editForm").hide();
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        var o = mini.decode(text);
                        form.setData(o);
                        mini.getbyName("cu_user").disable();
                    },
                    error: function () {
                        form.unmask();
                        ShowMessage("系统提示", "信息加载出错！", 3);
                    }
                });
            }
        }

        //保存基地企业
        function updateRow() {
            var form = new mini.Form("#editForm");
            form.validate();
            if (form.isValid() == false)
                return;
            var o = form.getData();
            var json = mini.encode(o);
            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });

            $.ajax({
                url: "../data/system.aspx?method=SaveBase",
                type: "post",
                data: { data: json },
                success: function (ret) {
                    mini.unmask(document.body);
                    if (ret == "out") {
                        var loginWindow = parent.mini.get("loginWindow");
                        if (!loginWindow.visible)
                            loginWindow.show();
                        return;
                    }
                    if (ret == 1) {
                        $("#divList").show();
                        $("#editForm").hide();
                        form.clear();
                        ShowMessage("系统提示", "基地企业保存成功！", 1);
                        grid.reload();
                    }
                    else if (ret == 0) {
                        $("#divList").show();
                        $("#editForm").hide();
                        form.clear();
                        ShowMessage("系统提示", "该基地企业已不存在，请确认！", 2);
                        grid.reload();
                        creatHtml();
                    }
                    else if (ret == 2) {
                        ShowMessage("系统提示", "该基地企业已存在，请确认！", 2);
                    }
                    else
                        ShowMessage("系统提示", "基地企业保存失败！", 3);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    mini.unmask(document.body);
                    ShowMessage("系统提示", "基地企业保存失败！", 3);
                }
            });
        }

        //取消基地企业
        function cancelRow() {
            var form = new mini.Form("#editForm");
            form.clear();
            $("#divList").show();
            $("#editForm").hide();
        }

        //删除基地企业
        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                mini.confirm("删除基地企业的同时将会删除该企业的相关信息，<br>确定删除该基地企业吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            $.ajax({
                                url: "../data/system.aspx?method=DeleteCompany",
                                data: { id: row.cu_no },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "基地企业删除成功！", 1);
                                        grid.reload();
                                        creatHtml();
                                    }
                                    else
                                        ShowMessage("系统提示", "基地企业删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "基地企业删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
        }

        //批量删除基地企业
        function delRows() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                mini.confirm("删除基地企业的同时会删除企业的相关信息录，<br>确定删除所选基地企业吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].cu_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=DeleteCompany",
                                type: "post",
                                data: { id: ids },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "基地企业删除成功！", 1);
                                        grid.reload();
                                        creatHtml();
                                    }
                                    else
                                        ShowMessage("系统提示", "基地企业删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "基地企业删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            } else
                ShowMessage("系统提示", "请选择需要删除的基地企业！", 2);
        }

        //批量免审/取消基地企业
        function freeRows(state) {
            var rows = grid.getSelecteds();
            var msg = "免审";
            if (state == 0)
                msg = "取消免审";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选基地企业吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].cu_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=OkCompany",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "基地企业" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "基地企业" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "基地企业" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            } else
                ShowMessage("系统提示", "请选择需要" + msg + "的基地企业！", 2);
        }

        function retRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var form = new mini.Form("#passform");
                var win = mini.get("passWindow");
                if (!win.visible)
                    win.show();
                form.loading();
                form.clear();
                $.ajax({
                    url: "../data/system.aspx?method=GetCompany",
                    data: { id: row.cu_no },
                    success: function (text) {
                        form.unmask();
                        if (text == "out") {
                            win.hide();
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        var o = mini.decode(text);
                        mini.get("cu_no2").setValue(o.cu_no);
                        $("#check").html(o.cu_name);
                    },
                    error: function () {
                        form.unmask();
                        ShowMessage("系统提示", "信息加载出错！", 3);
                    }
                });
            }
        }

        //关闭密码重置
        function closePass() {
            var win = mini.get("passWindow");
            var form = new mini.Form("#passform");
            form.clear();
            if (win.visible)
                win.hide();
        }

        //密码重置
        function updatePass() {
            var win = mini.get("passWindow");
            var form = new mini.Form("#passform");
            form.validate();
            if (form.isValid() == false)
                return;
            var o = form.getData();
            var json = mini.encode(o);
            var pass1 = mini.get("cu_password").getValue();
            var pass2 = mini.get("cu_password2").getValue();
            if (pass1 != pass2) {
                ShowMessage("系统提示", "两次密码不一致！", 1);
                return;
            }

            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });
            $.ajax({
                url: "../data/system.aspx?method=ResetBasePass",
                type: "post",
                data: { data: json },
                success: function (ret) {
                    mini.unmask(document.body);
                    if (ret == "out") {
                        var loginWindow = parent.mini.get("loginWindow");
                        if (!loginWindow.visible)
                            loginWindow.show();
                        return;
                    }
                    if (ret == 1) {
                        win.hide();
                        ShowMessage("系统提示", "密码重置成功！", 1);
                    }
                    else if (ret == 0) {
                        win.hide();
                        ShowMessage("系统提示", "该基地企业已不存在，请确认！", 2);
                        grid.reload();
                    }
                    else
                        ShowMessage("系统提示", "密码重置失败！", 3);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    mini.unmask(document.body);
                    ShowMessage("系统提示", "密码重置失败！", 3);
                }
            });
        }


        function excelRow() {
            mini.confirm("确定导出基地企业吗？", "系统提示",
                function (action) {
                    if (action == "ok") {
                        $("#excelForm").submit();
                    }
                }
            );
        }

        //招聘显示
        function onRecruitRenderer(e) {
            var s = '<a class="linelink" title="详细" href="javascript:void(0);" onclick="recruitRows(' + e.record._uid + ')">管理</a> (' + e.value + ')';
            return s;
        }

        //管理招聘
        function recruitRows(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var tabs = parent.mini.get("mainTabs");
                var tab = tabs.getTab("tab$704");
                tab.enabled = false;
                showRTab(row.cu_no);
            }
        }

        //打开管理招聘Tab
        function showRTab(cu_no) {
            var tabs = parent.mini.get("mainTabs");
            var id = "tab$int";
            var tab = tabs.getTab(id);
            if (!tab) {
                tab = {};
                tab.name = id;
                tab.title = "见习实习职位管理";
                tab.showCloseButton = true;
                tab.url = "student/interns.html?cuno=" + cu_no;
                tabs.addTab(tab);
            }
            tabs.activeTab(tab);
        }
    </script>
</html>
